--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--[[

    制服相关 功能直接 移植来

    常驻50%减伤。
    过冷时消耗 xx电量（饥饿）让温度升至65，
    过热时消耗 xx电量（饥饿）变成5度。

]]--
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- 参数
    local UNIFORM_TEMPERATURE_COST = TUNING["loramia.Config"].LORAMIA_UNIFORM_TEMPERATURE_COST or 200
    local UNIFORM_TAKEN_DAMAGE_MULT = TUNING["loramia.Config"].LORAMIA_UNIFORM_DAMAGETAKEN_MULT or 0.5
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

return function(inst)
    if not TheWorld.ismastersim then
        return
    end
    ------------------------------------------------------------------------------------------------------
    --- 创建虚拟实体
        local uniform_inst = CreateEntity()
        inst:ListenForEvent("onremove",function()
            uniform_inst:Remove()
        end)
        local uniform_equipped = false
    ------------------------------------------------------------------------------------------------------
    inst:ListenForEvent("loramia_master_postinit",function()
    ------------------------------------------------------------------------------------------------------
    --- 常驻50%减伤
            inst.components.combat.externaldamagetakenmultipliers:SetModifier(uniform_inst,UNIFORM_TAKEN_DAMAGE_MULT)
    ------------------------------------------------------------------------------------------------------
    --- 怪物的san光环加倍
            inst.components.sanity:SetNegativeAuraImmunity(1.3)
    ------------------------------------------------------------------------------------------------------
    --- 
        uniform_equipped = true
    ------------------------------------------------------------------------------------------------------
    end)
    ------------------------------------------------------------------------------------------------------
    --- 过冷过热 温度控制
        inst:ListenForEvent("temperaturedelta",function()
            -------------------------------------------------------------------
            --
                if inst:HasTag("playerghost") or not uniform_equipped then
                    return
                end
            -------------------------------------------------------------------
            --
                local need_2_cost_flag = false
                if inst.components.hunger.current < UNIFORM_TEMPERATURE_COST then
                    return
                end
            -------------------------------------------------------------------
            --
                local current = inst.components.temperature.current
                if current >= 65 then -- 过热
                    inst.components.temperature:SetTemperature(8)
                    inst:SpawnChild("halloween_firepuff_cold_2")
                    need_2_cost_flag = true
                elseif current <= 5 then
                    inst:SpawnChild("halloween_firepuff_1")
                    inst.components.temperature:SetTemperature(60)
                    need_2_cost_flag = true
                end
            -------------------------------------------------------------------
            --
                if need_2_cost_flag then
                    inst.components.hunger:DoDelta(-UNIFORM_TEMPERATURE_COST,true)
                end
            -------------------------------------------------------------------
        end)
    ------------------------------------------------------------------------------------------------------


end